package javaDemo11.多线程;

public class BOX {
    private int milk = 0;

    private boolean stats = false;

    public synchronized void put(int milk){
        if(stats){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.milk = milk;
        System.out.println("送奶工送了" + milk + "瓶奶");

        stats = true;
        notifyAll();
    }
    public synchronized void get(){
        if(!stats){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("用户拿到了" + milk + "瓶奶");

        stats = false;
        notifyAll();
    }
}

